package org.brownflat.fxdate.data;

import org.brownflat.dbinit.upgrade.Upgrade;
import org.springframework.stereotype.Component;

/**
 * <p>&copy Rupert Jones 2011,2012</p>
 *
 * @author rup
 */
@Component
public class Upgrade0001CreateUser implements Upgrade {

    private static final int VERSION = 1;

    @Override
    public int getSequence() {
        return VERSION;
    }

    @Override
    public String getSql() {
        StringBuffer sql = new StringBuffer();
        sql.append("CREATE TABLE FXDATE_USER " +
                "(ID NUMBER NOT NULL," +
                "USERNAME VARCHAR2(255 BYTE) NOT NULL," +
                "PASSWORD VARCHAR2(255 BYTE) NOT NULL," +
                "FULL_NAME VARCHAR2(255 BYTE) NOT NULL," +
                "CREATED_AT TIMESTAMP DEFAULT SYSDATE NOT NULL," +
                "UPDATED_AT TIMESTAMP DEFAULT SYSDATE NOT NULL);");

        sql.append("ALTER TABLE FXDATE_USER ADD CONSTRAINT FXD_CONST_USERNAME UNIQUE(\"USERNAME\")");
        return sql.toString();
    }

    @Override
    public String getName() {
        return "Create user table";
    }
}
